<!DOCTYPE html>
<html>
<head>
    <div th:include="base-libs :: base-libs" />
    <title>慢病管理台账</title>

    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">

    <style>
        .spanBtn{
            font-weight: bold;
            color: blue;
            cursor:pointer;
        }
        .laydate-icon{
            height:30px;
            border-color:#B6B6B6
        }
        .timeLeft{
            width:36% !important;
        }
        .timeSpan{
            display:inline-block;
            width:4%;
        }
        .timeRight{
            width:36% !important;
            float:right;
        }
    </style>
    <script>
        var mblxArr,wxfcArr,sfjgArr,sffsArr;
        $(function(){
            initView();
            $(this).registerManagerPage({cacheTables:["TB_ZY_WXFC","TB_ZY_SFJG","TB_ZY_SFFS"]
                ,callback:initData});
        })

        function initData(){
            mblxArr = StoreCache.getCache("TB_ZY_MBLX").data;
            wxfcArr = StoreCache.getCache("TB_ZY_WXFC").data;
            sfjgArr = StoreCache.getCache("TB_ZY_SFJG").data;
            sffsArr = StoreCache.getCache("TB_ZY_SFFS").data;
            $("#btnQuery").trigger("click");
        }

        function initView() {
            //回车查询
            enterToQuery(btnQueryHandler);

            /** 数据列表  */
            $("#centerTb").datagrid({
                idField : "ID",
                rownumbers: true,
                striped : true,
                clickToSelect: true,
                fitColumns: true,
                singleSelect: true,
                fit:true,
                scrollbarSize:17, //预留的滚动条的宽度
                columns : [[
                    {field : "SFSJ",title : "随访时间",width:80,align:'center',formatter:function(value){
                        if(!StringUtils.isEmpty(value)) return value.substring(0,10);
                    }},
                    {field : "HZXM",title : "患者姓名",width:80,align:'center'},
                    {field : "SFZH",title : "证件号码",width:140,align:'center',formatter:function(value,row,index){
                        if(!StringUtils.isEmpty(value)){
                            var reg = /.{8}$/;
                            return value.replace(reg,'********')
                        }
                    }},
                    {field : "MBLX",title : "慢病类型",width:100,align:'center',formatter:function(value){
                        $.each(mblxArr, function(){
                            if(this.XMDM==value){
                                value = this.XMMC;
                                return false;
                            }
                        })
                        return value;
                    }},
                    {field : "WXFC",title : "危险分层",width:80,align:'center',formatter:function(value){
                        $.each(wxfcArr, function(){
                            if(this.XMDM==value){
                                value = this.XMMC;
                                return false;
                            }
                        })
                        return value;
                    }},
                    {field : "GJZB",title : "关键指标",width:180,align:'left',formatter:function(value){
                        return '<span title="'+ value +'">'+value+'</span>';
                    }},
                    {field : "SFJG",title : "随访结果",width:80,align:'center',formatter:function(value){
                        $.each(sfjgArr, function(){
                            if(this.XMDM==value){
                                value = this.XMMC;
                                return false;
                            }
                        })
                        return value;
                    }},
                    {field : "SFFS",title : "随访方式",width:80,align:'center',formatter:function(value){
                        $.each(sffsArr, function(){
                            if(this.XMDM==value){
                                value = this.XMMC;
                                return false;
                            }
                        })
                        return value;
                    }},
                    {field : "SFYS",title : "随访医生",width:80,align:'center',formatter:function(value){
                        return '<span title="'+ value +'">'+value+'</span>';
                    }},
                    {field : "cz",title : "操作",width:60,align:'center', formatter:function(value,row){
                        var xg = '<span class="btnXg spanBtn">修改</span>';
                        var sc = '<span class="btnSc spanBtn" id="' + row.ID + '">删除</span>';
                        return xg + "&nbsp;&nbsp;" + sc;
                    }}
                ]],
                pagination : true,
                pageNumber : 1,
                pageSize : 10,
                pageList: [10, 20, 30, 50, 100],
                method : "post",
                onBeforeLoad : function(params) {
                    var options = $(this).datagrid("options");
                    if(!StringUtils.isEmpty(options.url)){
                        getContainerDataByClassName('conditionBox','condition',params);//查询条件
                    }
                },
            });

            /** 修改记录 */
            $("body").on("click",".btnXg",function(){
                var select = $("#centerTb").datagrid("getSelected");
                StoreCache.setCache("mbgltzData",select);

                parent.layer.open({
                    type: 2,
                    area: ["60%", "260px"],
                    content: contextRoot + 'mbgltz/update.html',
                    scrollbar: false,
                    resize: false,
                    title:'修改',
                    end: function(){
                        if(StoreCache.removeCache("refresh")){
                            $("#btnQuery").trigger("click");
                        }
                    }
                });
            })

            /** 删除记录 */
            $("body").on("click",".btnSc",function(){
                var delParams = {ID: $(this).attr("id")}
                $.QuickAlert.alertConfirm({
                    content : "删除后不可恢复，是否确认删除该数据？",
                    callback : function() {

                        $.QuickRemote.AjaxJson("delete", function (result) {
                            if(result.state){
                                $.QuickAlert.alertNormal(result.info, {callback: function(){
                                    $("#btnQuery").trigger("click");
                                }});
                            }else{
                                $.QuickAlert.alertFail({content: result.info});
                            }
                        }, delParams);
                    }
                })
            })
            //开始时间与结束时间的互相限制
            timeSetting('startTime','stopTime');
        }

        //时间段互相限制
        function timeSetting(startTagId,endTagId){
            var startTimeObj = {
                elem: '#'+ startTagId ,
                choose: function(datas){
                    endTimeObj.min = datas;
                }
            };
            laydate(startTimeObj);

            var endTimeObj = {
                elem: '#'+ endTagId,
                choose: function(datas){
                    startTimeObj.max = datas;
                }
            };
            laydate(endTimeObj);
        }

        /** 查询  */
        function btnQueryHandler(){
            $("#centerTb").datagrid({"url": contextRoot + "mbgltz/queryPage.service"});
        }

        /** 跳转到新增页面 */
        function toManager(row){
            $.QuickUrlUtils.redirectUrl("manager.html");
        }
    </script>

</head>

<body>
<div class="easyui-layout" fit="true" border="false" id="layout">
    <div region="north" style="overflow:hidden;padding:15px 0px;background:#f4f4f4;height:70px;" border="false" id="north">
        <table class="form-table" id="conditionBox">
            <tr>
                <td class="td-text">患者姓名：</td>
                <td class="td-content">
                    <input class="form-control condition"  name="HZXM" style="width: 100%;">
                </td>
                <td class="td-text">慢病类型：</td>
                <td class="td-content">
                    <select name="MBLX" class="form-control condition" style="width: 100%;" cacheTable="TB_ZY_MBLX">
                        <option value="">请选择</option>
                    </select>
                </td>
                <td class="td-text">随访时间：</td>
                <td class="td-content">
                    <input id="startTime" name="SFSJ_start" class="laydate-icon condition timeLeft"/>
                    <span class="timeSpan">-</span>
                    <input id="stopTime" name="SFSJ_end" class="laydate-icon condition timeRight"/>
                </td>
                <td class="td-text" style="width:170px;text-align:center">
                    <button id="btnQuery" class="btn btn-info" type="button" onclick="btnQueryHandler()">查询</button>
                    <button id="btnXz" class="btn btn-info" type="button" onclick="toManager()">新增</button>
                </td>
            </tr>
        </table>
    </div>
    <div region="center" border="false">
        <table id="centerTb" border="false"></table>
    </div>
</div>

</body>
</html>
